
import Router from "../function/route/route";


// 实例化路由对象
const router = new Router();

// 注册路由和处理程序

router.registerRoute("/hello", "GET", (req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end(JSON.stringify(router.getUrlParams(req)));
});

router.registerRoute("/hello/world", "GET", (req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("Hello World!");
});

router.registerRoute("/about", "GET", (req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("About Page");
});

router.registerRoute("/about/get", "GET", (req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("About get Page");
});



// router.registerRoute('/home', 'GET', (req, res) => {
//   res.writeHead(200, { 'Content-Type': 'text/plain' });
//   res.end('Hello!');
// }, [
//   {
//     path: '/user',
//     method: 'GET',
//     handler: (req, res) => {
//       res.writeHead(200, { 'Content-Type': 'text/plain' });
//       res.end('user77!');
//     },
//     subRoute: [
//       {
//         path: '/username',
//         method: 'GET',
//         handler: (req, res) => {
//           res.writeHead(200, { 'Content-Type': 'text/plain' });
//           res.end('Liubingxue');
//         },
//       },
//     ],
//   },
// ]);

// 创建HTTP服务器  端口默认为3000
router.createServer();
